<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://www.5imoban.net/download/jquery/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../common/bootstrap/bootstrap-4.4.0-dist/js/bootstrap.js"></script>
<link href="../css/chuqi.css" rel="stylesheet" type="text/css">
<title>信息管理系统</title>
<style>
.alt td {
	background: black !important;
}

.title {
	position: absolute;
	left: 1%;
	top: 10%;
	width: 98%;
	height: 20%;
	font-size: 32px;
}

.title_name {
	position: absolute;
	left: 0;
	width: 10%;
	font-size: 32px;
}

.subject_name {
	position: absolute;
	left: 10%;
	font-size: 32px;
}

.des {
	position: absolute;
	left: 1%;
	top: 25%;
	width: 98%;
	height: 30%;
}

.des_title {
	position: absolute;
	top: -5px;
	left: 0;
	width: 10%;
	font-size: 32px;
}

.subject_des {
	position: absolute;
	top: 0;
	left: 10%;
	width: 80%;
	height: 100%;
	font-size: 24px;
}

.submit_btn {
	position: absolute;
	top: 80%;
	right: 10.3%;
	font-size: 24px;
}

.upload {
	position: absolute;
	top: 60%;
	left: 0;
	width: 98%;
	height: 40px;
}

.upload_label {
	position: absolute;
	top: 0;
	left: 1%;
	width: 10%;
	line-height: 40px;
	font-size: 32px;
}

.upload_div {
	position: absolute;
	top: 0;
	left: 11%;
	line-height: 40px;
	height: 40px;
	width: 100px;
	color: white;
	background-color: #9370DB;
	border: 1px solid;
	border-radius: 25px;
	display: block;
}

.upload_btn {
	position: absolute;
	top: 0;
	left: 20px;
	opacity: 0;
	cursor: pointer;
	height: 100%;
	width: 100%;
	z-index: 10;
	display: block;
}
.download{
	position: absolute;
	top: 60%;
	left: 0;
	width: 98%;
	height: 40px;
	display: none;
}
.download_label{
	position: absolute;
	top: 0;
	left: 1%;
	width: 10%;
	line-height: 40px;
	font-size: 32px;
}
.download_div{
	position: absolute;
	top: 2px;
	left: 11%;
	line-height: 40px;
	height: 40px;
	width: 500px;
	text-align:left;
}
.download_commit{
	top: 8px;
	margin-left: 20px;
}
</style>
</head>
<body style="">
	<div class="neibu">
		<div class="row" id="title">请填写论文题目的相关信息！</div>
		<div class="row" style="width: 98%;">
			<form id="thesissysForm" enctype="multipart/form-data">
				<div class="title">
					<span class="title_name">论文题目：</span> <input type="text"
						class="subject_name" id="subject_name" name="subject_name">
				</div>
				<div class="des">
					<span class="des_title">题目简述：</span>
					<textarea class="subject_des" id="subject_des" name="subject_des"></textarea>
				</div>
				<div class="upload">
					<span id="upload_label" class="upload_label">上传文件：</span>
					<div class="upload_div">
						选择文档 <input type="file" name="subject_file" class="upload_btn" id="file">
					</div>
					<span id="ps">(注:鼠标放在选择文档上方浮现当前文件)</span>
				</div>
				<div class="download">
					<span id="download_label" class="download_label">当前文件：</span>
					<div class="download_div">
						<input type="button" class="download_commit" onclick="download()" value="下 载">
					</div>
				</div>
				<div>
					<input type="button" class="submit_btn" id="submit_btn" value="保存">
				</div>
			</form>
		</div>
	</div>
</body>
<script type="text/javascript">
	var action = sessionStorage.getItem("action");
	var sbj_name = sessionStorage.getItem("sbj_name");
	var sbj_describe = sessionStorage.getItem("sbj_describe");
	var sbj_id = sessionStorage.getItem("sbj_id") ? sessionStorage.getItem("sbj_id") : null;
	$(document).ready(function(){
		if(action == "add"){
			$("#subject_name").val("");
			$("#subject_des").text("");
		}
		else if(action == "edit"){
			$("#subject_name").val(sbj_name);
			$("#subject_des").text(sbj_describe);
		}
		else if(action == "view"){
			$("#subject_name").val(sbj_name);
			$("#subject_name").attr("readOnly",true);
			$("#subject_des").text(sbj_describe);
			$("#subject_des").attr("readOnly",true);
			$("#submit_btn").css("display","none");
			$(".upload").css("display","none");
			$("#ps").css("display","none");
			$(".download").css("display","block");
		}
	})
	$("#submit_btn").click(function() {
		if(action == "add"){
			var form = new FormData();
			var file_obj = document.getElementById("file").files[0];
			if (file_obj) {
				form.append("file", file_obj, file_obj.name);
			}else{
				form.append("file", null);
			}
			form.append("sbj_name", $("#subject_name").val());
			form.append("sbj_describe", $("#subject_des").val());
			form.append("sbj_status", "ct01");
			$.ajax({
				type : 'post',
				url : '/Teacher/save',
				contentType: false,
				processData: false,
				cache : false,
				async : false,
				data : form,
				dataType : 'JSON',
				success : function(data) {
					alert('保存成功!');
					window.history.back(-1);
				},
				error : function(data) {
					alert("保存失败!");
				}
			})
		}
		else if(action == "edit"){
			var form = new FormData();
			var file_obj = document.getElementById("file").files[0];
			if (file_obj) {
				form.append("file", file_obj, file_obj.name);
			}else{
				form.append("file", null);
			}
			form.append("sbj_id", sbj_id);
			form.append("sbj_name", $("#subject_name").val());
			form.append("sbj_describe", $("#subject_des").val());
			form.append("sbj_status", "ct01");
			$.ajax({
				type : 'post',
				url : '/Teacher/updatesbj',
				contentType: false,
				processData: false,
				cache : false,
				async : false,
				data : form,
				dataType : 'JSON',
				success : function(data) {
					alert('更新成功!');
					window.history.back(-1);
				},
				error : function(data) {
					alert("更新失败!");
				}
			})
		}
	})
	function download(){
		window.location.href = "download?sbj_id=" + sbj_id;
	}
</script>
</html>
